package com.jingbian.cppccbackend.mapper.admin;

import com.jingbian.cppccbackend.entity.Activities;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author yezi
 * @since 2025-03-04
 */
@Mapper
public interface adminActivitiesMapper extends BaseMapper<Activities> {

    List<Activities> getActivities( String sortType, String startDate, String endDate, String status, String searchText);

    @Update("UPDATE activities SET status = #{status} WHERE aid = #{aid}")
    boolean updateStatus(Integer aid, String status);


    @Select("SELECT a.*, u.uname, u.phone FROM activities a " +
            "JOIN users u ON a.user_id = u.uid WHERE a.aid = #{aid}")
    Activities getActivityWithUserDetails(Integer aid);

    // 获取活动总数
    @Select("SELECT COUNT(*) FROM activities")
    Integer getTotalActivities();

    // 获取昨日新增活动数
    @Select("SELECT COUNT(*) FROM activities WHERE DATE(created_at) = DATE_SUB(CURDATE(), INTERVAL 1 DAY)")
    Integer getNewActivitiesYesterday();

    // 获取活动成果总数
    @Select("SELECT COUNT(*) FROM activity_outcomes")
    Integer getTotalOutcomes();

    // 获取活动发布趋势
    List<Map<String, Object>> getActivityTrend(String startDate, String endDate);
}
